{extend name="common/common"/}

{block name="content-header"}
<h1>
    添加商品
    <small>Optional description</small>
</h1>
<ol class="breadcrumb">
    <li><a href="#"><i class="fa fa-dashboard"></i> Level</a></li>
    <li class="active">Here</li>
</ol>
{/block}

{block name="content"}
<form method="post" id="form-add">
    <div class="row">
        <div class="col-md-9">
            <div class="form-group">
                <input type="text" name="title" value="" class="form-control input-lg" placeholder="名称">
            </div>
            <div class="form-group">
                <textarea type="text" name="summary" rows="20" class="form-control" placeholder="描述"></textarea>
            </div>
            <div class="form-group">
                <!--<script type="text/plain" id="content" name="content"></script>-->
            </div>

        </div>
        <div class="col-md-3">
            <div class="box box-solid">
                <div class="box-header with-border">
                    <h3 class="box-title">添加</h3>
                    <div class="box-tools pull-right">
                        <button type="button" class="btn btn-box-tool" data-widget="collapse"><i class="fa fa-minus"></i></button>
                    </div>
                </div>
                <div class="box-body">
                    <div class="form-group">
                        <label class="control-label text-left">状态：</label>
                        <select name="status" class="form-control" style="width: auto; display: inline-block;">
                            <option value="1" >正常</option>
                            <option value="2" >已下架</option>
                        </select>
                    </div>
                </div>
                <div class="box-footer clearfix">
                    <button type="button" id="submit" class="btn btn-primary pull-right">添加</button>
                </div>
            </div>
            <!--/box-->
            <div class="box box-solid">
                <div class="box-header with-border">
                    <h3 class="box-title">分类目录</h3>
                    <div class="box-tools pull-right">
                        <button type="button" class="btn btn-box-tool" data-widget="collapse"><i class="fa fa-minus"></i></button>
                    </div>
                </div>
                <div class="box-body">

                    <div class="category-div">
                        <div class="nav-tabs-custom-custom">
                            <ul class="nav nav-tabs">
                                <li class="active"><a href="#tab_1" data-toggle="tab" aria-expanded="true">所有分类目录</a></li>
                            </ul>
                            <div class="tab-content">
                                <div class="tab-pane active" id="tab_1">

                                    <div class="category-check-list">
                                        <ul>
                                            {volist name="cates" id="v"}
                                            <li><label><input type="radio" name="cid" value="{$v['id']}"> <span>{$v['name']}</span></label></li>
                                            {/volist}
                                        </ul>
                                    </div>

                                </div>
                                <!-- /.tab-pane -->
                            </div>
                            <!-- /.tab-content -->
                        </div>
                    </div>

                </div>
            </div>
            <!--/.box-->



            <div class="box box-solid">
                <div class="box-header with-border">
                    <h3 class="box-title">封面图片</h3>
                    <div class="box-tools pull-right">
                        <button type="button" class="btn btn-box-tool" data-widget="collapse"><i class="fa fa-minus"></i></button>
                    </div>
                </div>
                <div class="box-body">
                    <textarea id="_editor" class="hidden"></textarea>

                    <div class="row" id="post-thumbnails">
                        <!--
                        <div class="col-xs-6 post-thumbnail">
                            <div class="alert">
                                <input type="hidden" name="thumbnails[]" value="http://tiantiankandian.test.upcdn.net/uploads/20171107/d01be5c636123ec30a8a15b58468711e.jpg">
                                <div style="background-image: url(http://tiantiankandian.test.upcdn.net/uploads/20171107/d01be5c636123ec30a8a15b58468711e.jpg); width: 100%; height: 162.25px; background-size: cover;"></div>
                                <button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                            </div>
                        </div>
                        <div class="col-xs-6 post-thumbnail">
                            <div class="alert">
                                <input type="hidden" name="thumbnails[]" value="http://tiantiankandian.test.upcdn.net/uploads/20171107/8177a93b49f950bb9d4f0ca8f67e29d2.jpg">
                                <div style="background-image: url(http://tiantiankandian.test.upcdn.net/uploads/20171107/8177a93b49f950bb9d4f0ca8f67e29d2.jpg); width: 100%; height: 162.25px; background-size: cover;"></div>
                                <button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                            </div>
                        </div>
                        <div class="col-xs-6 post-thumbnail">
                            <div class="alert">
                                <input type="hidden" name="thumbnails[]" value="http://tiantiankandian.test.upcdn.net/uploads/20171107/53cfa37d9071a3d5e1fa503539d20da8.jpg">
                                <div style="background-image: url(http://tiantiankandian.test.upcdn.net/uploads/20171107/53cfa37d9071a3d5e1fa503539d20da8.jpg); width: 100%; height: 162.25px; background-size: cover;"></div>
                                <button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                            </div>
                        </div>
                        <div class="col-xs-6 post-thumbnail">
                            <div class="alert">
                                <input type="hidden" name="thumbnails[]" value="http://tiantiankandian.test.upcdn.net/uploads/20171107/448e3d12d398bd8ed58a3b3d5a949f2c.jpg">
                                <div style="background-image: url(http://tiantiankandian.test.upcdn.net/uploads/20171107/448e3d12d398bd8ed58a3b3d5a949f2c.jpg); width: 100%; height: 162.25px; background-size: cover;"></div>
                                <button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                            </div>
                        </div>
                        -->
                    </div>

                    <a href="javascript:void(0);" id="set-thumbnails">设置封面图片</a>
                </div>
            </div>
            <!--/.box-->
        </div>
    </div>
</form>
{/block}

{block name="footer"}
<script src="__ROOT__/static/console/plugins/layer/layer.js"></script>
<script type="text/javascript" charset="utf-8" src="__ROOT__/static/common/ueditor/ueditor.config.js"></script>
<script type="text/javascript" charset="utf-8" src="__ROOT__/static/common/ueditor/ueditor.all.js"></script>
<script>
    $(function(){
        var url = "{:url( 'ueditor.local/index')}";

        // 文章内容
        var ue = UE.getEditor('content', {
            serverUrl: url
        });

        // 封面图片
        var _editor = UE.getEditor('_editor', {
            serverUrl: url
        });
        _editor.ready(function () {
            _editor.hide();
            _editor.addListener('beforeInsertImage', function ( t, arg ) {
                console.log( arg );

                var cols = '';
                for ( var i = 0; i < arg.length; i++ ) {
                    cols += '<div class="col-xs-6 post-thumbnail alert">';

                    cols += '<input type="hidden" name="head_img[]" value="' + arg[i].src + '">';
                    cols += '<img src="' + arg[i].src + '" alt="" width="100%">';

                    cols += '<button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button>';
                    cols += '</div>';
                }
                $( "#post-thumbnails ").append( cols );
            });
        });
        $( "#set-thumbnails" ).on("click", function () {
            var insertImage = _editor.getDialog("insertimage");
            insertImage.open();
        });

        $('#submit').click(function () {
            var url = "{:url('goods/insert')}";
            $.ajax({
                url: url,
                dataType: 'json',
                type: 'post',
                data: $('#form-add').serialize(),
                success: function (data) {
                    if (data.status == 'success') {
                        layer.ready(function(){
                            layer.msg('添加成功');
                            location.href="{:url('goods/index')}"
                        });
                    } else {
                        layer.ready(function(){
                            layer.msg(data.info, function () {

                            });
                        });
                    }
                }
            })
        })
    });
</script>
{/block}